package net.common;

/**
 * @Author admin
 * @Date 2019/4/2 9:38
 */
public class ServiceResponse<E> {
     private int status;
     private String message;
     private E data;

    private ServiceResponse(int status, String message, E data) {
        this.status = status;
        this.message = message;
        this.data = data;
    }

    private ServiceResponse(int status, E data) {
        this.status = status;
        this.data = data;
    }

    private ServiceResponse(int status, String message) {
        this.status = status;
        this.message = message;
    }

    private ServiceResponse(int status) {
        this.status = status;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public E getData() {
        return data;
    }

    public void setData(E data) {
        this.data = data;
    }

    //成功，状态
    public static <E> ServiceResponse createSuccessStatus(){
        return new ServiceResponse<>(ResposeCode.SUCCESS.getStatus());
    }
    //成功，数据
    public static <E> ServiceResponse createSuccessAndData(E data){
        return new ServiceResponse<>(ResposeCode.SUCCESS.getStatus(),data);
    }
    //成功，消息
    public static <E> ServiceResponse createSuccessAndMessage(String message){
        return new ServiceResponse<>(ResposeCode.SUCCESS.getStatus(),message);
    }
    //成功，状态，消息
    public static <E> ServiceResponse createSuccessByMessageAndData(String message,E data){
        return new ServiceResponse<>(ResposeCode.SUCCESS.getStatus(),message,data);
    }

    //失败，状态
    public static <E> ServiceResponse createErrorStatus(){
        return new ServiceResponse<>(ResposeCode.ERROR.getStatus());
    }
    //失败，数据
    public static <E> ServiceResponse createErrorAndData(E data){
        return new ServiceResponse<>(ResposeCode.ERROR.getStatus(),data);
    }
    //失败，消息
    public static <E> ServiceResponse createErrorAndMessage(String message){
        return new ServiceResponse<>(ResposeCode.ERROR.getStatus(),message);
    }
    //失败，状态，消息
    public static <E> ServiceResponse createErrorByMessageAndData(String message,E data){
        return new ServiceResponse<>(ResposeCode.ERROR.getStatus(),message,data);
    }

    //异常，状态
    public static <E> ServiceResponse createIllegal_argumentStatus(){
        return new ServiceResponse<>(ResposeCode.ILLEGAL_ARGUMENT.getStatus());
    }
    //异常，数据
    public static <E> ServiceResponse createIllegal_argumentAndData(E data){
        return new ServiceResponse<>(ResposeCode.ILLEGAL_ARGUMENT.getStatus(),data);
    }
    //异常，消息
    public static <E> ServiceResponse createIllegal_argumentAndMessage(String message){
        return new ServiceResponse<>(ResposeCode.ILLEGAL_ARGUMENT.getStatus(),message);
    }
    //异常，状态，消息
    public static <E> ServiceResponse createIllegal_argumentByMessageAndData(String message,E data){
        return new ServiceResponse<>(ResposeCode.ILLEGAL_ARGUMENT.getStatus(),message,data);
    }

}
